﻿//
// © Algobox Ltd - Benn Eichhorn
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Algobox.Structure.Finance.Strategies.SpikeArb;
using System.Windows.Controls;
using Algobox.Structure.Finance.Strategies.Terrapin;
using Algobox.Structure.Finance.Strategies;
using Algobox.Structure.Finance.Strategies.Dastan;
using Algobox.Structure.Finance.Strategies.Moss;

namespace Zephyr
{
    public class ZephyrDataGridSorter : System.Collections.IComparer
    {
        public ZephyrDataGridSorter(ListSortDirection direction, DataGridColumn column)
        {
            _direction = direction;
            _column = column;
            _sortProperty = (string)column.SortMemberPath;
        }

        ListSortDirection _direction;
        DataGridColumn _column;
        string _sortProperty;
        
        public int Compare(object x, object y)
        {
            // do SpikeArbStockView
            SpikeArbStockView viewX = x as SpikeArbStockView;
            if (viewX != null)
            {
                SpikeArbStockView viewY = y as SpikeArbStockView;
                switch (_sortProperty)
                {
                    case "Symbol":
                        return _direction == ListSortDirection.Ascending ? viewX.Symbol.CompareTo(viewY.Symbol) : viewY.Symbol.CompareTo(viewX.Symbol);
                    case "IsEnabled":
                        return _direction == ListSortDirection.Ascending ? viewX.IsEnabled.CompareTo(viewY.IsEnabled) : viewY.IsEnabled.CompareTo(viewX.IsEnabled);
                    case "IsEnabledPrimary":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.IsEnabledPrimary.CompareTo(viewY.IsEnabledPrimary);
                        return viewY.IsEnabledPrimary.CompareTo(viewX.IsEnabledPrimary);
                    case "IsEnabledChix":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.IsEnabledChix.CompareTo(viewY.IsEnabledChix);
                        return viewY.IsEnabledChix.CompareTo(viewX.IsEnabledChix);
                    case "IsEnabledBats":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.IsEnabledBats.CompareTo(viewY.IsEnabledBats);
                        return viewY.IsEnabledBats.CompareTo(viewX.IsEnabledBats);
                    case "Collar1Enabled":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar1Enabled.CompareTo(viewY.Collar1Enabled);
                        return viewY.Collar1Enabled.CompareTo(viewX.Collar1Enabled);
                    case "Collar2Enabled":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar2Enabled.CompareTo(viewY.Collar2Enabled);
                        return viewY.Collar2Enabled.CompareTo(viewX.Collar2Enabled);
                    case "Collar3Enabled":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar3Enabled.CompareTo(viewY.Collar3Enabled);
                        return viewY.Collar3Enabled.CompareTo(viewX.Collar3Enabled);
                    case "Collar4Enabled":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar4Enabled.CompareTo(viewY.Collar4Enabled);
                        return viewY.Collar4Enabled.CompareTo(viewX.Collar4Enabled);
                    case "Collar1Pct":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar1Pct.CompareTo(viewY.Collar1Pct);
                        return viewY.Collar1Pct.CompareTo(viewX.Collar1Pct);
                    case "Collar1Val":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar1Val.CompareTo(viewY.Collar1Val);
                        return viewY.Collar1Val.CompareTo(viewX.Collar1Val);
                    case "Collar1Win":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar1Win.CompareTo(viewY.Collar1Win);
                        return viewY.Collar1Win.CompareTo(viewX.Collar1Win);
                    case "Collar2Pct":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar2Pct.CompareTo(viewY.Collar2Pct);
                        return viewY.Collar2Pct.CompareTo(viewX.Collar2Pct);
                    case "Collar2Val":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar2Val.CompareTo(viewY.Collar2Val);
                        return viewY.Collar2Val.CompareTo(viewX.Collar2Val);
                    case "Collar2Win":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar2Win.CompareTo(viewY.Collar2Win);
                        return viewY.Collar2Win.CompareTo(viewX.Collar2Win);
                    case "Collar3Pct":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar3Pct.CompareTo(viewY.Collar3Pct);
                        return viewY.Collar3Pct.CompareTo(viewX.Collar3Pct);
                    case "Collar3Val":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar3Val.CompareTo(viewY.Collar3Val);
                        return viewY.Collar3Val.CompareTo(viewX.Collar3Val);
                    case "Collar3Win":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar3Win.CompareTo(viewY.Collar3Win);
                        return viewY.Collar3Win.CompareTo(viewX.Collar3Win);
                    case "Collar4Pct":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar4Pct.CompareTo(viewY.Collar4Pct);
                        return viewY.Collar4Pct.CompareTo(viewX.Collar4Pct);
                    case "Collar4Val":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar4Val.CompareTo(viewY.Collar4Val);
                        return viewY.Collar4Val.CompareTo(viewX.Collar4Val);
                    case "Collar4Win":
                        if (_direction == ListSortDirection.Ascending)
                            return viewX.Collar4Win.CompareTo(viewY.Collar4Win);
                        return viewY.Collar4Win.CompareTo(viewX.Collar4Win);
                    default:
                        return 0;
                }                
            }

            // do TerrapinConfig
            TerrapinStock terrapinStockX = x as TerrapinStock;            
            if (terrapinStockX != null)
            {
                TerrapinStock terrapinStockY = y as TerrapinStock;
                switch(_sortProperty)
                {
                    case "Security":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.Security.ToString().CompareTo(terrapinStockY.Security.ToString());
                        return (terrapinStockY.Security.ToString()).CompareTo(terrapinStockX.Security.ToString());
                    case "IsEnabled":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.IsEnabled.CompareTo(terrapinStockY.IsEnabled);
                        return (terrapinStockY.IsEnabled).CompareTo(terrapinStockX.IsEnabled);
                    case "DatabaseId":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.DatabaseId.CompareTo(terrapinStockY.DatabaseId);
                        return (terrapinStockY.DatabaseId).CompareTo(terrapinStockX.DatabaseId);
                    case "UnitValue":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.UnitValue.CompareTo(terrapinStockY.UnitValue);
                        return (terrapinStockY.UnitValue).CompareTo(terrapinStockX.UnitValue);
                    case "Phase":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.Phase.CompareTo(terrapinStockY.Phase);
                        return (terrapinStockY.Phase).CompareTo(terrapinStockX.Phase);
                    case "Sector":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.Sector.CompareTo(terrapinStockY.Sector);
                        return (terrapinStockY.Sector).CompareTo(terrapinStockX.Sector);
                    case "EntryBars":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.EntryBars.CompareTo(terrapinStockY.EntryBars);
                        return (terrapinStockY.EntryBars).CompareTo(terrapinStockX.EntryBars);
                    case "ExitBars":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.ExitBars.CompareTo(terrapinStockY.ExitBars);
                        return (terrapinStockY.ExitBars).CompareTo(terrapinStockX.ExitBars);
                    case "FastEMA":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.FastEMA.CompareTo(terrapinStockY.FastEMA);
                        return (terrapinStockY.FastEMA).CompareTo(terrapinStockX.FastEMA);
                    case "SlowSMA":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.SlowSMA.CompareTo(terrapinStockY.SlowSMA);
                        return (terrapinStockY.SlowSMA).CompareTo(terrapinStockX.SlowSMA);
                    case "Last":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.Last.CompareTo(terrapinStockY.Last);
                        return (terrapinStockY.Last).CompareTo(terrapinStockX.Last);
                    case "High":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.High.CompareTo(terrapinStockY.High);
                        return (terrapinStockY.High).CompareTo(terrapinStockX.High);
                    case "Low":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.Low.CompareTo(terrapinStockY.Low);
                        return (terrapinStockY.Low).CompareTo(terrapinStockX.Low);
                    case "MAFast":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.MAFast.CompareTo(terrapinStockY.MAFast);
                        return (terrapinStockY.MAFast).CompareTo(terrapinStockX.MAFast);
                    case "MASlow":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.MASlow.CompareTo(terrapinStockY.MASlow);
                        return (terrapinStockY.MASlow).CompareTo(terrapinStockX.MASlow);
                    case "Filter":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinStockX.Filter.ToString().CompareTo(terrapinStockY.Filter.ToString());
                        return (terrapinStockY.Filter.ToString()).CompareTo(terrapinStockX.Filter.ToString());
                    default:
                        return 0;
                }
            }

            // do Terrapin Executions
            TerrapinUnit terrapinUnitX = x as TerrapinUnit;
            if (terrapinUnitX != null)
            {
                TerrapinUnit terrapinUnitY = y as TerrapinUnit;
                switch (_sortProperty)
                {
                    case "Strategy":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinUnitX.Strategy.ToString().CompareTo(terrapinUnitY.Strategy.ToString());
                        return (terrapinUnitY.Strategy.ToString()).CompareTo(terrapinUnitX.Strategy.ToString());
                    case "Id":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinUnitX.Id.CompareTo(terrapinUnitY.Id);
                        return (terrapinUnitY.Id).CompareTo(terrapinUnitX.Id);
                    case "Name":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinUnitX.Name.CompareTo(terrapinUnitY.Name);
                        return (terrapinUnitY.Name).CompareTo(terrapinUnitX.Name);
                    case "Direction":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinUnitX.Direction.CompareTo(terrapinUnitY.Direction);
                        return (terrapinUnitY.Direction).CompareTo(terrapinUnitX.Direction);
                    case "Quantity":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinUnitX.Quantity.CompareTo(terrapinUnitY.Quantity);
                        return (terrapinUnitY.Quantity).CompareTo(terrapinUnitX.Quantity);
                    case "Remaining":
                        if (_direction == ListSortDirection.Ascending)
                            return terrapinUnitX.Remaining.CompareTo(terrapinUnitY.Remaining);
                        return (terrapinUnitY.Remaining).CompareTo(terrapinUnitX.Remaining);
                    case "EntryTarget":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.EntryTarget).CompareTo(terrapinUnitY.EntryTarget);
                        return (terrapinUnitY.EntryTarget).CompareTo(terrapinUnitX.EntryTarget);
                    case "EntryActual":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.EntryActual).CompareTo(terrapinUnitY.EntryActual);
                        return (terrapinUnitY.EntryActual).CompareTo(terrapinUnitX.EntryActual);
                    case "ExitTarget":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.ExitTarget).CompareTo(terrapinUnitY.ExitTarget);
                        return (terrapinUnitY.ExitTarget).CompareTo(terrapinUnitX.ExitTarget);
                    case "ExitActual":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.ExitActual).CompareTo(terrapinUnitY.ExitActual);
                        return (terrapinUnitY.ExitActual).CompareTo(terrapinUnitX.ExitActual);
                    case "Profit":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.Profit).CompareTo(terrapinUnitY.Profit);
                        return (terrapinUnitY.Profit).CompareTo(terrapinUnitX.Profit);
                    case "SlipEntry":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.SlipEntry).CompareTo(terrapinUnitY.SlipEntry);
                        return (terrapinUnitY.SlipEntry).CompareTo(terrapinUnitX.SlipEntry);
                    case "SlipExit":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.SlipExit).CompareTo(terrapinUnitY.SlipExit);
                        return (terrapinUnitY.SlipExit).CompareTo(terrapinUnitX.SlipExit);
                    case "TimeStampEntry":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.TimeStampEntry).CompareTo(terrapinUnitY.TimeStampEntry);
                        return (terrapinUnitY.TimeStampEntry).CompareTo(terrapinUnitX.TimeStampEntry);
                    case "TimeStampExit":
                        if (_direction == ListSortDirection.Ascending)
                            return (terrapinUnitX.TimeStampExit).CompareTo(terrapinUnitY.TimeStampExit);
                        return (terrapinUnitY.TimeStampExit).CompareTo(terrapinUnitX.TimeStampExit);                        
                    default:
                        return 0;
                }
            }


            

            // do Dastan Config
            DastanStock dastanStockX = x as DastanStock;            
            if (dastanStockX != null)
            {
                DastanStock dastanStockY = y as DastanStock;
                switch(_sortProperty)
                {
                    case "Security":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.Security.ToString().CompareTo(dastanStockY.Security.ToString());
                        return (dastanStockY.Security.ToString()).CompareTo(dastanStockX.Security.ToString());
                    case "IsEnabled":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.IsEnabled.CompareTo(dastanStockY.IsEnabled);
                        return (dastanStockY.IsEnabled).CompareTo(dastanStockX.IsEnabled);
                    case "DatabaseId":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.DatabaseId.CompareTo(dastanStockY.DatabaseId);
                        return (dastanStockY.DatabaseId).CompareTo(dastanStockX.DatabaseId);
                    case "UnitValue":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.UnitValue.CompareTo(dastanStockY.UnitValue);
                        return (dastanStockY.UnitValue).CompareTo(dastanStockX.UnitValue);
                    case "Phase":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.Phase.CompareTo(dastanStockY.Phase);
                        return (dastanStockY.Phase).CompareTo(dastanStockX.Phase);
                    case "Sector":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.Sector.CompareTo(dastanStockY.Sector);
                        return (dastanStockY.Sector).CompareTo(dastanStockX.Sector);
                    case "EntryBars":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.EntryBars.CompareTo(dastanStockY.EntryBars);
                        return (dastanStockY.EntryBars).CompareTo(dastanStockX.EntryBars);
                    case "ExitBars":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.ExitBars.CompareTo(dastanStockY.ExitBars);
                        return (dastanStockY.ExitBars).CompareTo(dastanStockX.ExitBars);
                    case "AveragePeriod":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.AveragePeriod.CompareTo(dastanStockY.AveragePeriod);
                        return (dastanStockY.AveragePeriod).CompareTo(dastanStockX.AveragePeriod);
                    case "TicksPerBar":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.TicksPerBar.CompareTo(dastanStockY.TicksPerBar);
                        return (dastanStockY.TicksPerBar).CompareTo(dastanStockX.TicksPerBar);
                    case "Last":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.Last.CompareTo(dastanStockY.Last);
                        return (dastanStockY.Last).CompareTo(dastanStockX.Last);
                    case "High":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.High.CompareTo(dastanStockY.High);
                        return (dastanStockY.High).CompareTo(dastanStockX.High);
                    case "Low":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.Low.CompareTo(dastanStockY.Low);
                        return (dastanStockY.Low).CompareTo(dastanStockX.Low);
                    case "MAFast":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.MAFast.CompareTo(dastanStockY.MAFast);
                        return (dastanStockY.MAFast).CompareTo(dastanStockX.MAFast);
                    case "MASlow":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.MASlow.CompareTo(dastanStockY.MASlow);
                        return (dastanStockY.MASlow).CompareTo(dastanStockX.MASlow);
                    case "Filter":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanStockX.Filter.ToString().CompareTo(dastanStockY.Filter.ToString());
                        return (dastanStockY.Filter.ToString()).CompareTo(dastanStockX.Filter.ToString());
                    default:
                        return 0;
                }
            }

            // do Dastan Executions
            DastanUnit dastanUnitX = x as DastanUnit;
            if (dastanUnitX != null)
            {
                DastanUnit dastanUnitY = y as DastanUnit;
                switch (_sortProperty)
                {
                    case "Strategy":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanUnitX.Strategy.ToString().CompareTo(dastanUnitY.Strategy.ToString());
                        return (dastanUnitY.Strategy.ToString()).CompareTo(dastanUnitX.Strategy.ToString());
                    case "Id":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanUnitX.Id.CompareTo(dastanUnitY.Id);
                        return (dastanUnitY.Id).CompareTo(dastanUnitX.Id);
                    case "Name":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanUnitX.Name.CompareTo(dastanUnitY.Name);
                        return (dastanUnitY.Name).CompareTo(dastanUnitX.Name);
                    case "Direction":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanUnitX.Direction.CompareTo(dastanUnitY.Direction);
                        return (dastanUnitY.Direction).CompareTo(dastanUnitX.Direction);
                    case "Quantity":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanUnitX.Quantity.CompareTo(dastanUnitY.Quantity);
                        return (dastanUnitY.Quantity).CompareTo(dastanUnitX.Quantity);
                    case "Remaining":
                        if (_direction == ListSortDirection.Ascending)
                            return dastanUnitX.Remaining.CompareTo(dastanUnitY.Remaining);
                        return (dastanUnitY.Remaining).CompareTo(dastanUnitX.Remaining);
                    case "EntryTarget":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.EntryTarget).CompareTo(dastanUnitY.EntryTarget);
                        return (dastanUnitY.EntryTarget).CompareTo(dastanUnitX.EntryTarget);
                    case "EntryActual":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.EntryActual).CompareTo(dastanUnitY.EntryActual);
                        return (dastanUnitY.EntryActual).CompareTo(dastanUnitX.EntryActual);
                    case "ExitTarget":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.ExitTarget).CompareTo(dastanUnitY.ExitTarget);
                        return (dastanUnitY.ExitTarget).CompareTo(dastanUnitX.ExitTarget);
                    case "ExitActual":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.ExitActual).CompareTo(dastanUnitY.ExitActual);
                        return (dastanUnitY.ExitActual).CompareTo(dastanUnitX.ExitActual);
                    case "Profit":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.Profit).CompareTo(dastanUnitY.Profit);
                        return (dastanUnitY.Profit).CompareTo(dastanUnitX.Profit);
                    case "SlipEntry":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.SlipEntry).CompareTo(dastanUnitY.SlipEntry);
                        return (dastanUnitY.SlipEntry).CompareTo(dastanUnitX.SlipEntry);
                    case "SlipExit":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.SlipExit).CompareTo(dastanUnitY.SlipExit);
                        return (dastanUnitY.SlipExit).CompareTo(dastanUnitX.SlipExit);
                    case "TimeStampEntry":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.TimeStampEntry).CompareTo(dastanUnitY.TimeStampEntry);
                        return (dastanUnitY.TimeStampEntry).CompareTo(dastanUnitX.TimeStampEntry);
                    case "TimeStampExit":
                        if (_direction == ListSortDirection.Ascending)
                            return (dastanUnitX.TimeStampExit).CompareTo(dastanUnitY.TimeStampExit);
                        return (dastanUnitY.TimeStampExit).CompareTo(dastanUnitX.TimeStampExit);                        
                    default:
                        return 0;
                }
            }





            // do Moss Config
            MossStock mossStockX = x as MossStock;
            if (mossStockX != null)
            {
                MossStock mossStockY = y as MossStock;
                switch (_sortProperty)
                {
                    case "Security":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.Security.ToString().CompareTo(mossStockY.Security.ToString());
                        return (mossStockY.Security.ToString()).CompareTo(mossStockX.Security.ToString());
                    case "IsEnabled":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.IsEnabled.CompareTo(mossStockY.IsEnabled);
                        return (mossStockY.IsEnabled).CompareTo(mossStockX.IsEnabled);
                    case "DatabaseId":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.DatabaseId.CompareTo(mossStockY.DatabaseId);
                        return (mossStockY.DatabaseId).CompareTo(mossStockX.DatabaseId);
                    case "UnitValue":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.UnitValue.CompareTo(mossStockY.UnitValue);
                        return (mossStockY.UnitValue).CompareTo(mossStockX.UnitValue);
                    case "Phase":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.Phase.CompareTo(mossStockY.Phase);
                        return (mossStockY.Phase).CompareTo(mossStockX.Phase);
                    case "Last":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.Last.CompareTo(mossStockY.Last);
                        return (mossStockY.Last).CompareTo(mossStockX.Last);
                    case "RSI":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.RSI.CompareTo(mossStockY.RSI);
                        return (mossStockY.RSI).CompareTo(mossStockX.RSI);
                    case "RSIBottom":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.RSIBottom.CompareTo(mossStockY.RSIBottom);
                        return (mossStockY.RSIBottom).CompareTo(mossStockX.RSIBottom);
                    case "RSIRetrace":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.RSIRetrace.CompareTo(mossStockY.RSIRetrace);
                        return (mossStockY.RSIRetrace).CompareTo(mossStockX.RSIRetrace);
                    case "RSITop":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.RSITop.CompareTo(mossStockY.RSITop);
                        return (mossStockY.RSITop).CompareTo(mossStockX.RSITop);
                    case "Average":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.Average.CompareTo(mossStockY.Average);
                        return (mossStockY.Average).CompareTo(mossStockX.Average);
                    case "BollyHigh":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.BollyHigh.CompareTo(mossStockY.BollyHigh);
                        return (mossStockY.BollyHigh).CompareTo(mossStockX.BollyHigh);
                    case "BollyLow":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.BollyLow.CompareTo(mossStockY.BollyLow);
                        return (mossStockY.BollyLow).CompareTo(mossStockX.BollyLow);
                    case "BollyPeriod":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.BollyPeriod.CompareTo(mossStockY.BollyPeriod);
                        return (mossStockY.BollyPeriod).CompareTo(mossStockX.BollyPeriod);
                    case "BollySTDEV":
                        if (_direction == ListSortDirection.Ascending)
                            return mossStockX.BollySTDEV.CompareTo(mossStockY.BollySTDEV);
                        return (mossStockY.BollySTDEV).CompareTo(mossStockX.BollySTDEV);
                    default:
                        return 0;
                }
            }

            // do Moss Executions
            MossUnit mossUnitX = x as MossUnit;
            if (mossUnitX != null)
            {
                MossUnit mossUnitY = y as MossUnit;
                switch (_sortProperty)
                {
                    case "Strategy":
                        if (_direction == ListSortDirection.Ascending)
                            return mossUnitX.Strategy.ToString().CompareTo(mossUnitY.Strategy.ToString());
                        return (mossUnitY.Strategy.ToString()).CompareTo(mossUnitX.Strategy.ToString());
                    case "Id":
                        if (_direction == ListSortDirection.Ascending)
                            return mossUnitX.Id.CompareTo(mossUnitY.Id);
                        return (mossUnitY.Id).CompareTo(mossUnitX.Id);
                    case "Name":
                        if (_direction == ListSortDirection.Ascending)
                            return mossUnitX.Name.CompareTo(mossUnitY.Name);
                        return (mossUnitY.Name).CompareTo(mossUnitX.Name);
                    case "Direction":
                        if (_direction == ListSortDirection.Ascending)
                            return mossUnitX.Direction.CompareTo(mossUnitY.Direction);
                        return (mossUnitY.Direction).CompareTo(mossUnitX.Direction);
                    case "Quantity":
                        if (_direction == ListSortDirection.Ascending)
                            return mossUnitX.Quantity.CompareTo(mossUnitY.Quantity);
                        return (mossUnitY.Quantity).CompareTo(mossUnitX.Quantity);
                    case "Remaining":
                        if (_direction == ListSortDirection.Ascending)
                            return mossUnitX.Remaining.CompareTo(mossUnitY.Remaining);
                        return (mossUnitY.Remaining).CompareTo(mossUnitX.Remaining);
                    case "EntryTarget":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.EntryTarget).CompareTo(mossUnitY.EntryTarget);
                        return (mossUnitY.EntryTarget).CompareTo(mossUnitX.EntryTarget);
                    case "EntryActual":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.EntryActual).CompareTo(mossUnitY.EntryActual);
                        return (mossUnitY.EntryActual).CompareTo(mossUnitX.EntryActual);
                    case "ExitTarget":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.ExitTarget).CompareTo(mossUnitY.ExitTarget);
                        return (mossUnitY.ExitTarget).CompareTo(mossUnitX.ExitTarget);
                    case "ExitActual":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.ExitActual).CompareTo(mossUnitY.ExitActual);
                        return (mossUnitY.ExitActual).CompareTo(mossUnitX.ExitActual);
                    case "Profit":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.Profit).CompareTo(mossUnitY.Profit);
                        return (mossUnitY.Profit).CompareTo(mossUnitX.Profit);
                    case "SlipEntry":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.SlipEntry).CompareTo(mossUnitY.SlipEntry);
                        return (mossUnitY.SlipEntry).CompareTo(mossUnitX.SlipEntry);
                    case "SlipExit":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.SlipExit).CompareTo(mossUnitY.SlipExit);
                        return (mossUnitY.SlipExit).CompareTo(mossUnitX.SlipExit);
                    case "TimeStampEntry":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.TimeStampEntry).CompareTo(mossUnitY.TimeStampEntry);
                        return (mossUnitY.TimeStampEntry).CompareTo(mossUnitX.TimeStampEntry);
                    case "TimeStampExit":
                        if (_direction == ListSortDirection.Ascending)
                            return (mossUnitX.TimeStampExit).CompareTo(mossUnitY.TimeStampExit);
                        return (mossUnitY.TimeStampExit).CompareTo(mossUnitX.TimeStampExit);
                    default:
                        return 0;
                }
            }


            // do Strategy Unit Summary
            StrategyUnitSummary unitSummaryX = x as StrategyUnitSummary;
            if (unitSummaryX != null)
            {
                StrategyUnitSummary unitSummaryY = y as StrategyUnitSummary;
                switch (_sortProperty)
                {
                    case "Name":
                        if (_direction == ListSortDirection.Ascending)
                            return unitSummaryX.Name.CompareTo(unitSummaryY.Name);
                        return unitSummaryY.Name.CompareTo(unitSummaryX.Name);
                    case "Position":
                        if (_direction == ListSortDirection.Ascending)
                            return unitSummaryX.Position.CompareTo(unitSummaryY.Position);
                        return unitSummaryY.Position.CompareTo(unitSummaryX.Position);
                    case "UnrealPL":
                        if (_direction == ListSortDirection.Ascending)
                            return unitSummaryX.UnrealPL.CompareTo(unitSummaryY.UnrealPL);
                        return unitSummaryY.UnrealPL.CompareTo(unitSummaryX.UnrealPL);
                    case "RealPL":
                        if (_direction == ListSortDirection.Ascending)
                            return unitSummaryX.RealPL.CompareTo(unitSummaryY.RealPL);
                        return unitSummaryY.RealPL.CompareTo(unitSummaryX.RealPL);
                    case "NetPL":
                        if (_direction == ListSortDirection.Ascending)
                            return unitSummaryX.NetPL.CompareTo(unitSummaryY.NetPL);
                        return unitSummaryY.NetPL.CompareTo(unitSummaryX.NetPL);
                    default:
                        return 0;
                }
            }
            
            // do Spike Executions Summary
            SpikeArbFill spikeFillX = x as SpikeArbFill;
            if (spikeFillX != null)
            {
                SpikeArbFill spikeFillY = y as SpikeArbFill;
                switch (_sortProperty)
                {
                    case "Stock":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Stock.CompareTo(spikeFillY.Stock);
                        return spikeFillY.Stock.CompareTo(spikeFillX.Stock);
                    case "Direction":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Direction.CompareTo(spikeFillY.Direction);
                        return spikeFillY.Direction.CompareTo(spikeFillX.Direction);
                    case "Collar":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Collar.CompareTo(spikeFillY.Collar);
                        return spikeFillY.Collar.CompareTo(spikeFillX.Collar);
                    case "Exit":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Exit.CompareTo(spikeFillY.Exit);
                        return spikeFillY.Exit.CompareTo(spikeFillX.Exit);
                    case "Price":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Price.CompareTo(spikeFillY.Price);
                        return spikeFillY.Price.CompareTo(spikeFillX.Price);
                    case "Quantity":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Quantity.CompareTo(spikeFillY.Quantity);
                        return spikeFillY.Quantity.CompareTo(spikeFillX.Quantity);
                    case "Remaining":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Remaining.CompareTo(spikeFillY.Remaining);
                        return spikeFillY.Remaining.CompareTo(spikeFillX.Remaining);
                    case "Target":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Target.CompareTo(spikeFillY.Target);
                        return spikeFillY.Target.CompareTo(spikeFillX.Target);
                    case "TargetPL":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.TargetPL.CompareTo(spikeFillY.TargetPL);
                        return spikeFillY.TargetPL.CompareTo(spikeFillX.TargetPL);
                    case "Stop":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Stop.CompareTo(spikeFillY.Stop);
                        return spikeFillY.Stop.CompareTo(spikeFillX.Stop);
                    case "StopPL":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.StopPL.CompareTo(spikeFillY.StopPL);
                        return spikeFillY.StopPL.CompareTo(spikeFillX.StopPL);
                    case "Realised":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Realised.CompareTo(spikeFillY.Realised);
                        return spikeFillY.Realised.CompareTo(spikeFillX.Realised);
                    case "RealisedPL":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.RealisedPL.CompareTo(spikeFillY.RealisedPL);
                        return spikeFillY.RealisedPL.CompareTo(spikeFillX.RealisedPL);
                    case "Slippage":
                        if (_direction == ListSortDirection.Ascending)
                            return spikeFillX.Slippage.CompareTo(spikeFillY.Slippage);
                        return spikeFillY.Slippage.CompareTo(spikeFillX.Slippage);
                    default:
                        return 0;
                }
            }

            // do Price Matrix
            

            return 0;
        }
    }
}
